<h1>Cr&eacute;ation d'un pilote</h1>

<?php if((empty($_POST['nomPilote']))||(empty($_POST['prenomPilote']))||(empty($_POST['ecuriePilote']))||(empty($_POST['paysPilote'])))
		{
?>

	<?php 
		$pays = new pays() ;
		$listePays = $pays->getAllNationalites() ;
		$ecurie = new ecurie() ;
		$listeEcurie = $ecurie->getAllEcuries() ;
	?>
	<div class="floatStop">
	<form method="post" action="index.php?page=10" enctype="multipart/form-data" name="general" >
	<table>
		<tr>
			<td align="right" >Nom :</td>
			<td><input type="text" name="nomPilote" />*</td>
		</tr>
		<tr>
			<td align="right" >Pr&eacute;nom :</td>
			<td><input type="text" name="prenomPilote" />*</td>
		</tr>
		<tr>
			<td align="right" >Nationalit&eacute; :</td><td>
	    <select name="paysPilote" >
	    	<option value="0">Choix du pays</option>
	    	<?php 
	    		foreach($listePays as $ligne)
	    		{
	    			?>
	    			<option value=<?php echo $ligne->PAYNUM>$ligne->PAYNAT ; ?></option>
	    			<?php
	    		}
	    	?>
	    </select>*</td>
		</tr>
		<tr>
			<td align="right" >Date de naissance :</td>
			<td>
				<script>DateInput('orderdate', true, 'YYYY-MM-DD')</script>
				<!--input type="text" id="dateNaiss" name="dateNaiss" /-->
				<input type="button" onClick="document.getElementById('dateNaiss').value = this.form.orderdate.value" value="Show date value passed">	
				<script language="javascript">
				    
				</script>
			</td>
		</tr>
		<tr>
			<td align="right" >Poids :</td>
			<td><input type="text" name="poidsPilote" size="3" /> kg</td>
		</tr>
		<tr>
			<td align="right" >Taille :</td>
			<td><input type="text" name="taillePilote" size="3" /> cm</td>
		</tr>
		<tr>
			<td align="right" >Ecurie :</td><td>
	    <select name="ecuriePilote" >
	    	<option value="0">Choix de l'ecurie</option>
	    	<?php 
	    		foreach($listeEcurie as $ligne)
	    		{
	    			?>
	    			<option value=<?php echo $ligne->ECUNUM>$ligne->ECUNOM ; ?></option>
	    			<?php
	    		}
	    	?>
	    </select>*</td>
		</tr>
		<tr>
				<td align="right" >Image :</td>
				<td>
					<img src="images/util/defaut.png" /><br/>
					<input type="file" name="adrImage" />
				</td>
			</tr>
		<tr>
			<td align="right" >Description :</td>
			<td><textarea name="descriptionPilote" rows="10" cols="60"></textarea></td>
		</tr>
		<tr>
			<td align="right" ></td>
			<td>
				<input type="submit" /><input type="reset" />
			</td>
		</tr>
	</table>
	</form>
	</div>
<?php 	}

else 
		{
			$pilote = new pilote() ;
			$pilote->setNom(htmlentities(utf8_decode(addslashes($_POST['nomPilote'])))) ;
			$pilote->setPrenom(htmlentities(utf8_decode(addslashes($_POST['prenomPilote'])))) ;
			$pilote->setIdPays(htmlentities($_POST['paysPilote'])) ;
			
			$pilote->setDateNaiss($_POST['dateNaiss']) ;
			
			$pilote->setPoids(htmlentities($_POST['poidsPilote'])) ;
			$pilote->setTaille(htmlentities(utf8_decode($_POST['taillePilote']))) ;
			$pilote->setTexte(htmlentities(utf8_decode($_POST['descriptionPilote']))) ;
			$pilote->setIdEcurie(htmlentities(utf8_decode(addslashes($_POST['ecuriePilote'])))) ;
			$pilote->ajouterPilote() ;
			

			$dossier = 'images/pilote/' ;
			//$fichier = 'adrImage' ;
			
			$upload = new uploadUtil() ;
			$upload->upload($_FILES['adrImage'], $dossier) ;
			
			$photo = new photo() ;
			$ligne=$pilote->getIdPiloteByOthers();
			$photo->setIdPilote($ligne->PILNUM);
			$photo->setAdresse(htmlentities(utf8_encode(addslashes($_FILES['adrImage']['name'])))) ;
			$photo->ajouterPhotoIdentite() ;
						
			echo "Pilote ajout&eacute; ! " ;
			
			
		}
		
		?>